package test2;

public class Test7 {
    public static void main(String[] args) {
        int[] nums = new int[]{2, 5, 4, 6, 1, 7};
        int[] arr = quick_sort(nums, 0, nums.length - 1);
        for (int i : arr) {
            System.out.print(i + " ");
        }
    }

    private static int[] quick_sort(int[] nums, int begin, int end) {
        if (begin > end) {
            return nums;
        }
        int left = begin;
        int right = end;
        int key = nums[left];

        while (left < right) {
            while (left < right && nums[right] >= key) {
                right--;
            }
            nums[left] = nums[right];
            while (left < right && nums[left] <= key) {
                left++;
            }
            nums[right] = nums[left];
        }
        int meet = left;
        nums[meet] = key;
        quick_sort(nums, begin, meet - 1);
        quick_sort(nums, meet + 1, end);
        return nums;
    }
}
